#include <stdio.h>
#include <stdlib.h>
#include <fcntl.h>

int main(int argc, char const* argv[])
{
    int fd;
    struct flock lock;

    if (argc != 2)
    {
        printf("usage: %s <filename>\n", argv[0]);
        exit(0);
    }

    if ((fd = open(argv[1], O_RDWR)) < 0)
    {
        perror("open error");
        exit(0);
    }

    lock.l_type = F_WRLCK;
    lock.l_start = 0;
    lock.l_whence = SEEK_SET;
    lock.l_len = 1;
    lock.l_pid = getpid();
    if (fcntl(fd, F_SETLKW, &lock) < 0)
    {
        perror("fcntl error");
        exit(0);
    }

    printf("what? you add the lock!\n");

    return 0;
}
